<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <form action="" class="layui-form" lay-filter="virusForm">
        <input type="hidden"  id="virus_id" name="virus_id">
        <div class="layui-form layuimini-form" lay-filter="vaccineForm">
            <div class="layui-form-item">
                <label class="layui-form-label required">病毒名称</label>
                <div class="layui-input-block">
                    <input type="text" name="virus_name" id="virus_name" lay-verify="required" lay-reqtext="病毒名称不能为空"
                        placeholder="请输入病毒名称" value="" class="layui-input" >
                </div>
            </div>
            <!-- <div class="layui-form-item">
                <label class="layui-form-label required">病毒类型</label>
                <div class="layui-input-block">
                    <input type="text" name="virus_type" id="virus_type" lay-verify="required" lay-reqtext="病毒类型不能为空"
                        placeholder="请输入病毒类型" value="" class="layui-input" >
                </div>
            </div> -->

            <div class="layui-form-item">
                <label class="layui-form-label required">病毒类型</label>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <button class="layui-btn demo1">
                            <input type="hidden" class="layui-input" id="virus_type" name="virus_type" placeholder="请选择类型"
                                readonly>
                            <i class="layui-icon layui-icon-down layui-font-12" id="virus_type_i">病毒类型</i>
                        </button>
                    </div>
                </div>
            </div>
    

            <!-- <div class="layui-form-item">
                <label class="layui-form-label required">病毒信息</label>
                <div class="layui-input-block">
                    <input type="text" name="virus_message" lay-verify="required" lay-reqtext="疫苗品种不能为空"
                        placeholder="请输入疫苗品种" value="" class="layui-input">
                </div>
            </div> -->

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">病毒信息</label>
                <div class="layui-input-block">
                    <textarea name="virus_message" id="virus_message" class="layui-textarea" placeholder="请输入病毒信息内容"></textarea>
                    <!-- <textarea class="layui-textarea" name="virus_message" id="lay_content" style="display: none" placeholder="请输入病毒信息" readonly>
                    </textarea> -->
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </form>
    <script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'layedit', 'dropdown', 'util', 'table'], function () {
            var form = layui.form,
                layer = layui.layer,
                laydate = layui.laydate,
                layedit = layui.layedit,
                dropdown = layui.dropdown
            $ = layui.$;
            laydate.render({
                elem: '#date'
            });

 //构建一个默认的编辑器
 var index = layedit.build('lay_content');


            //初演示
            dropdown.render({
                elem: '.demo1'
                , data: [{
                    title: 'DNA'
                    , id: 100
                }, {
                    title: 'RNA'
                    , id: 101
                }, {
                    title: '其他'
                    , id: 102
                }]
                , click: function (obj) {
                    layer.tips('选择的是：' + obj.title, this.elem, { tips: [1, '#5FB878'] })
                    $("#virus_type").val(obj.title)
                    $("#virus_type_i").html(obj.title)
                }
            });




            //从localStorage 把数据取出来  赋值给表单项
            var jsonStr = localStorage.getItem("virus");
            var virusObj = JSON.parse(jsonStr);
            //给表单项赋值
            form.val("virusForm", {
                virus_id:virusObj.virus_id,
                virus_name:virusObj.virus_name,
                virus_type:virusObj.virus_type,
                virus_message:virusObj.virus_message
            });
            $("#virus_type_i").html(virusObj.virus_type)

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var index = layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }, function () {

                    // 关闭弹出层
                    layer.close(index);

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);

                });

                $.ajax({
                    url: "http://localhost:8080/admin/virus/virus/edit",
                    data: data.field,
                    type: 'post',
                    success: function (data) {
                        if (data.code == 200) {
                            parent.layer.msg("修改成功")

                        }
                    },
                    error: function (data) {
                        console.log("bbb = " + data)
                        layer.alert("修改失败!")
                    }
                });

                return false;
            });
        });
    </script>
</body>

</html>